-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.ts
50 lines (40 loc) · 1.22 KB
/
init.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Command, {flags} from '@oclif/command'
import * as fs from 'fs'
import {Files} from '../files'
const inquirer = require('../inquirer')
export class Init extends Command {
static description = 'Initializes the needed variables such as URLs and API keys'
static examples = [
`$ forge create
hello world from ./src/hello.ts!
`,
]
static flags = {
help: flags.help({char: 'h'}),
// flag with a value (-n, --name=VALUE)
name: flags.string({char: 'n', description: 'name to print'}),
// flag with no value (-f, --force)
force: flags.boolean({char: 'f'}),
}
static args = [{name: 'file'}]
async run() {
// Confirm file overwrite
if (Files.fileExists('.env')) {
const question = 'AskEnvFileOverwrite'
const confirm = await inquirer.askEnvFileOverwrite()
if (!confirm[question]) {
console.log('Aborting.')
this.exit()
}
}
const answers = await inquirer.askEnvInitializationVariables()
let fileOutput = ''
Object.keys(answers).map((key: string) => {
fileOutput += (key + '=' + answers[key] + '\n')
})
fs.writeFile('.env', fileOutput, function (err) {
if (err) throw err
console.log('init success.')
})
}
}